<template>
  <el-card class="box-card" style="height: 900px">
    <div slot="header">
      <el-menu default-active="1" active-text-color="#FF0000" class="el-menu-demo" mode="horizontal">
        <el-menu-item index="1">个人信息</el-menu-item>
      </el-menu>
    </div>
    <div style="width: 400px">
      <el-form :model="informationForm" ref="informationForm" label-width="100px">

        <el-form-item label="用户名" prop="uphone">
          <el-input :disabled="true" v-model="informationForm.uphone"></el-input>
        </el-form-item>
        <el-form-item label="昵称" prop="uname">
          <el-input v-model="informationForm.uname"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="usex">
          <el-radio-group v-model="informationForm.usex">
            <el-radio label="0">男</el-radio>
            <el-radio label="1">女</el-radio>
            <el-radio label="2">保密</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="地址" prop="uaddress">
          <el-input v-model="informationForm.uaddress"></el-input>
        </el-form-item>
        <el-form-item label="生日" prop="ubirthday">
          <!--<el-input v-model="informationForm.ubirthday"></el-input>-->
          <el-date-picker
            v-model="informationForm.ubirthday"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="头像" prop="uimage">
          <el-input v-show="false" v-model="informationForm.uimage"></el-input>
          <el-upload
            class="avatar-uploader"
            action="http://localhost:8899/student/stu/user/getImgPath"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload">
            <el-avatar v-if="informationForm.uimage" :src="informationForm.uimage"></el-avatar>
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('informationForm')">修改</el-button>
        </el-form-item>
      </el-form>
    </div>
  </el-card>
</template>

<script>
  import qs from 'qs'
  export default {
    name: "PersonInformation",
    data() {
      return {
        informationForm: {
          uid:'',
          uphone: '',
          unickname: '',
          usex: '',
          uaddress: '',
          ubirthday: '',
          headportrait: '',
          uimage:'',
        },
        //sessionTeacher:{},
        //sessionStudent:{}
      }
    },
    methods: {

      submitForm() {

           // alert('submit!');
            this.$axios2.post("/student/stu/user/updStudent",qs.stringify(this.informationForm)).then(r=>{
              if (r.data){
                this.$message.success("修改成功！！")
              }
            })
      },
      /*resetForm(formName) {
        this.$refs[formName].resetFields();
      },*/
      handleAvatarSuccess(res, file) {
        // this.informationForm.headportrait = URL.createObjectURL(file.raw);
        this.informationForm.uimage=res;
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === '';
        const isLt2M = file.size / 1024 / 1024 < 2;

        /*if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }*/
       // return isJPG && isLt2M;
      }
    },
    created() {
      let uid =sessionStorage.getItem("uid");
      this.$axios2.get("/student/stu/user/slectAll?uid="+uid).then(r => {
        this.informationForm=r.data;
        //alert(JSON.stringify(this.informationForm));
        console.log(r.data)
      })
    }
  }
</script>

<style scoped>

</style>
